const o = {a:1,address:{b:2}}
const px = new Proxy(o,{
  get(target, key, receiver) {
    console.log('get~~~~~~~~~~~');
    console.log('target:',target);
    console.log('key:',key);
    return target[key]
  },
  set(target,key,value,receiver){
    console.log('set~~~~~~~~~~~');
    console.log('target:',target);
    console.log('key:',key);
    console.log('value:',value);
  }
})

// px.a

// px.address
/*
get~~~~~~~~~~~
target: { a: 1, address: { b: 2 } }
key: address
*/

// px.address.b
/*
get~~~~~~~~~~~
target: { a: 1, address: { b: 2 } }
key: address
*/

px.address = 123;
// ↑只会触发set 不会触发get
/*
set~~~~~~~~~~~
target: { a: 1, address: { b: 2 } }
key: address
value: 123

*/
// 除非你 px.address.x = 123 这样赋值 ↓
// px.address.x = 123
/*
get~~~~~~~~~~~
target: { a: 1, address: { b: 2 } }
key: address
*/

//===================================

/*const handler = {
  get(target, key, receiver) {
    console.log('get~~~~~~~~~~~');
    console.log('target:',target);
    console.log('key:',key);

    if (typeof target[key] === 'object') {
      return new Proxy(target[key], handler);
    }

    return target[key];
  },
  set(target,key,value,receiver){
    console.log('set~~~~~~~~~~~');
    console.log('target:',target);
    console.log('key:',key);
    console.log('value:',value);
  }
}

const px = new Proxy(o,handler)

px.address.b*/
/*
get~~~~~~~~~~~
target: { a: 1, address: { b: 2 } }
key: address
get~~~~~~~~~~~
target: { b: 2 }
key: b
*/
